package com.tms.springboot.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.tms.springboot.aggregation.pojo.PdFleet;
import com.tms.springboot.result.JsonResult;

import com.tms.springboot.result.ResultTool;
import com.tms.springboot.service.PdFleetService;
import com.tms.springboot.utils.UUId;
import com.tms.springboot.view.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 车队表 前端控制器
 * </p>
 *
 * @author cjj
 * @since 2023-06-14
 */
@RestController
@RequestMapping("/pd-fleet")
public class PdFleetController {


    @Autowired
    private PdFleetService pdFleetServices;

    /**
     * 查询所有车队
     *
     * @return
     */
    @RequestMapping(value = "/queryCoreOrgListAll")
    public JsonResult queryCoreOrgListAll() {
        List<PdFleet> list = pdFleetServices.list();
        return list != null ? ResultTool.success(list) : ResultTool.fail();
    }

    /**
     * 条件分页查询
     *
     * @param pageVo
     * @return
     */
    @RequestMapping("/queryFleet")
    public JsonResult queryFleet(@RequestBody PageVo<PdFleet> pageVo) {
        LambdaQueryWrapper<PdFleet> lqw = new LambdaQueryWrapper<>();
        PageHelper.startPage(pageVo.getCurrentPage(), pageVo.getPageSize());
        if (!StringUtil.isEmpty(pageVo.getCondition().getName())) {
            lqw.like(PdFleet::getName, pageVo.getCondition().getName());
        }
        if (!StringUtil.isEmpty(pageVo.getCondition().getAgencyId())) {
            lqw.eq(PdFleet::getAgencyId, pageVo.getCondition().getAgencyId());
        }
        lqw.eq(PdFleet::getStatus, 1);
        List<PdFleet> list = pdFleetServices.list(lqw);

        return list != null ? ResultTool.success(new PageInfo<PdFleet>(list)) : ResultTool.fail();
    }




}
